<template>
  <div>
    <el-button type="primary" @click="willAdd">添加</el-button>
    <!-- 列表 -->
    <v-list :list="list" @edit="willEdit" @init="init"></v-list>
    <!-- 表单 -->
    <v-form
      :info="info"
      :list="list"
      @init="init"
      ref="form"
    ></v-form>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import vList from "./component/list";
import vForm from "./component/form";
import { reqmenulist } from "../../request/api";
export default {
  components: {
    vList,
    vForm,
  },
  data() {
    return {
      info: {
        isshow: false,
        isAdd:true
      },
      list: [],
    };
  },
  mounted() {
    this.init();
  },
  computed: {
    ...mapGetters({}),
  },
  methods: {
    ...mapActions({}),
    willAdd() {
      this.info.isshow = true;
      this.info.isAdd = true;
    },
    //进来请数据
    init() {
      reqmenulist({ istree: true }).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.list ? res.data.list : [];
        }
      });
    },
    //将要编辑
    willEdit(id) {
      //弹框出现
      this.info.isshow = true;
      this.info.isAdd = false;
      //通知form取数据
      this.$refs.form.getOne(id);
    },
  },
};
</script>

<style>
</style>